<template>
  <view class="detail-container">
    <view class="detail-header">
      <view class="title">{{notice.noticeTitle}}</view>
      <view class="info">
        <text class="type">{{notice.noticeType === '1' ? '通知' : '公告'}}</text>
        <text class="time">{{notice.createTime}}</text>
      </view>
    </view>
    <view class="detail-content">
      <rich-text :nodes="notice.noticeContent"></rich-text>
    </view>
  </view>
</template>

<script>
import { getNoticeById } from '@/api/notification.js'

export default {
  data() {
    return {
      notice: {
        noticeTitle: '',
        noticeContent: '',
        noticeType: '',
        createTime: '',
        status: '0'
      }
    }
  },
  onLoad(options) {
    if (options.id) {
      this.loadNoticeDetail(options.id)
    }
  },
  methods: {
    async loadNoticeDetail(id) {
      try {
        const res = await getNoticeById(id)
        if (res.code === 200) {
          this.notice = res.data
          // 标记为已读
          if (this.notice.status === '0') {
            this.notice.status = '1'
          }
        } else {
          uni.showToast({
            title: '获取详情失败',
            icon: 'none'
          })
        }
      } catch (error) {
        console.error('加载详情失败:', error)
        uni.showToast({
          title: '加载失败',
          icon: 'none'
        })
      }
    }
  }
}
</script>

<style lang="scss">
.detail-container {
  min-height: 100vh;
  background-color: #fff;
  padding: 30rpx;
}

.detail-header {
  margin-bottom: 40rpx;
}

.title {
  font-size: 36rpx;
  font-weight: 500;
  color: #333;
  margin-bottom: 20rpx;
}

.info {
  display: flex;
  align-items: center;
  font-size: 24rpx;
  color: #999;
}

.type {
  background-color: #f0f0f0;
  padding: 4rpx 12rpx;
  border-radius: 4rpx;
  margin-right: 20rpx;
}

.detail-content {
  font-size: 28rpx;
  color: #666;
  line-height: 1.6;
}
</style>